<template>
  <div class="order-list">
    <order-header title="订单列表">
      <template v-slot:tip>
        <span>请谨防钓鱼链接或诈骗电话，了解更多></span>
      </template>
    </order-header>
    <div class="wrapper">
      <div class="container">
        <div class="order-box">
          <div class="order" v-for="item in orderList" :key="item.orderNo">
            <div class="order-title">
              <div class="item-info fl">
                创建时间：{{ item.createTime }}
                <span>|</span>
                用户名：{{ username }}
                <span>|</span>
                订单号：{{ item.orderNo }}
                <span>|</span>
                {{ item.paymentType === 1 ? '在线支付' : '' }}
              </div>
              <div class="item-money fr">
                <span>应付金额：</span>
                <span class="money">{{ item.totalPrice }}</span>
                <span>元</span>
              </div>
            </div>
            <div class="order-content clearfix">
              <div class="good-box fl">
                <div class="good-list" v-for="childItem in item.orderItemVOList" :key="childItem.productId">
                  <div class="good-img">
                    <img
                        :src="childItem.productImg"
                        alt=""/>
                  </div>
                  <div class="good-name">
                    <div class="p-name">{{ childItem.productName }}</div>
                    <div class="p-money">
                      <span>{{ childItem.unitPrice }} </span>
                      X
                      <span>{{ childItem.quantity }}</span>
                    </div>
                    <div>小计：{{ childItem.totalPrice }}</div>
                  </div>
                </div>
              </div>
              <div class="good-state fr">
                <a href="javascript:;" v-if="item.orderStatusName === '未付款'" @click="handlePay(item.orderNo)">{{
                    item.orderStatusName
                  }}</a>
                <a href="javascript:;" v-else>{{ item.orderStatusName }}</a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import OrderHeader from './../components/OrderHeader';
import {
  getOrderList
} from '@/api/order';

export default {
  name: 'order-list',
  components: {
    OrderHeader,
  },
  data() {
    return {
      queryInfo: {
        pageNum: 1,
        pageSize: 10
      },
      username: this.$store.state.username,
      orderList: []
    };
  },
  created() {
    this.handleGetOrderList();
  },
  methods: {
    async handleGetOrderList() {
      const res = await getOrderList(this.queryInfo);
      console.log(res.data.list);
      if (res.data.list.length > 0) {
        this.orderList = res.data.list;
      }
    },
    handlePay(orderNo) {
      console.log(orderNo)
      this.$router.push({
        path: '/order/pay',
        query: {
          orderNo: orderNo
        }
      })
    }
  }
};
</script>
<style lang="scss">
@import './../assets/scss/config.scss';
@import './../assets/scss/mixin.scss';

.order-list {
  .wrapper {
    background-color: $colorJ;
    padding-top: 33px;
    padding-bottom: 110px;

    .order-box {
      .order {
        @include border();
        background-color: $colorG;
        margin-bottom: 31px;

        &:last-child {
          margin-bottom: 0;
        }

        .order-title {
          @include height(74px);
          background-color: $colorK;
          padding: 0 43px;
          font-size: 16px;
          color: $colorC;

          .item-info {
            span {
              margin: 0 9px;
            }
          }

          .money {
            font-size: 26px;
            color: $colorB;
          }
        }

        .order-content {
          padding: 0 43px;

          .good-box {
            width: 88%;

            .good-list {
              display: flex;
              align-items: center;
              height: 145px;

              .good-img {
                width: 112px;

                img {
                  width: 100%;
                }
              }

              .good-name {
                font-size: 20px;
                color: $colorB;
              }
            }
          }

          .good-state {
            @include height(145px);
            font-size: 20px;
            color: $colorA;

            a {
              color: $colorA;
            }
          }
        }
      }

      .pagination {
        text-align: right;
      }

      .el-pagination.is-background .el-pager li:not(.disabled).active {
        background-color: #ff6600;
      }

      .el-button--primary {
        background-color: #ff6600;
        border-color: #ff6600;
      }

      .load-more,
      .scroll-more {
        text-align: center;
      }
    }
  }
}
</style>
